package validate

import (
	"context"
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
)

// SECRET_KEY 共享密钥
const SECRET_KEY = "73cdf0d52a1eb401938b5a8a34c005b8"

type SignParam struct {
	Timestamp string
	Signature string
}

// VerifySignature 签名校验
func VerifySignature(ctx context.Context, param SignParam) bool {
	mac := hmac.New(sha256.New, []byte(SECRET_KEY))
	mac.Write([]byte(param.Timestamp))
	expectedSign := hex.EncodeToString(mac.Sum(nil))
	// 判断时间是否过期
	//timestamp, _ := strconv.Atoi(param.Timestamp)
	//if timestamp == 0 || time.Now().Add(-10*time.Second).Before(time.Unix(int64(timestamp), 0)) {
	//	return false
	//}
	return expectedSign == param.Signature
}
